package com.jackson.passjava.account.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jackson.passjava.account.entity.AccountEntity;
import com.jackson.passjava.account.service.AccountService;
import com.jackson.passjava.common.utils.PageUtils;
import com.jackson.passjava.common.utils.R;


/**
 * @author Liyuhang
 * @email 50875895@qq.com
 * @date 2021-08-23 17:08:49
 */
@RestController
@RequestMapping("account/account")
public class AccountController {

    private final AccountService accountService;

    @Autowired
    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = accountService.queryPage(params);
        return R.ok().put("page",page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        AccountEntity account = accountService.getById(id);
        return R.ok().put("account",account);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AccountEntity account) {
        accountService.save(account);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AccountEntity account) {
        accountService.updateById(account);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        accountService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }



    @RequestMapping("/updateById")
    public Boolean updateById(@RequestBody AccountEntity account) {
        return accountService.updateById(account);
    }


}
